package cn.com.generaldata.jsme_indicator_system.entity;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;

import lombok.Data;

import org.apache.commons.lang3.StringUtils;
import org.nutz.dao.entity.annotation.ColDefine;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Id;
import org.nutz.dao.entity.annotation.Many;
import org.nutz.dao.entity.annotation.Table;

import com.google.common.collect.Lists;

/**
 * 省海洋经济统计指标.
 */
@Data
@Table("t_indicator_province")
public class IndicatorProvince implements java.io.Serializable {

	private static final long serialVersionUID = -7047022527214283001L;

	// columns START
	/**
	 * PK db_column: id
	 */
	@Id
	@Column("id")
	private Integer id;
	/**
	 * 父id db_column: pid
	 */
	@Column("pid")
	private Integer pid;
	/**
	 * 指标代码 db_column: code
	 */
	@Column("code")
	private String code;
	/**
	 * 父指标代码 db_column: pcode
	 */
	@Column("pcode")
	private String pcode;
	/**
	 * 指标名称 db_column: name
	 */
	@Column("name")
	private String name;
	/**
	 * 对应制度指标id db_column: indicator_system_report_id
	 */
	@Column("indicator_system_report_id")
	private Integer indicatorSystemReportId;
	/**
	 * 国标码 db_column: national_standard_code
	 */
	@Column("national_standard_code")
	private String nationalStandardCode;
	/**
	 * 指标类别 db_column: category
	 */
	@Column("category")
	private Integer category;
	/**
	 * 监测频率 db_column: frequency
	 */
	@Column("frequency")
	private Integer frequency;
	/**
	 * 重要程度 db_column: importance
	 */
	@Column("importance")
	private Integer importance;
	/**
	 * 数据类型 db_column: data_type
	 */
	@Column("data_type")
	private Integer dataType;
	/**
	 * 计量单位 db_column: unit
	 */
	@Column("unit")
	private String unit;
	/**
	 * 计量单位数量级 db_column: unit_magnitude
	 */
	@Column("unit_magnitude")
	private Integer unitMagnitude;
	/**
	 * 指标汇总权重 db_column: weighted
	 */
	@Column("weighted")
	private BigDecimal weighted;
	/**
	 * 行业代码 db_column: industry_code
	 */
	@Column("industry_code")
	private String industryCode;
	/**
	 * 指标描述 db_column: description
	 */
	@Column("description")
	private String description;
	/**
	 * 创建时间 db_column: create_time
	 */
	@Column("create_time")
	@ColDefine(update = false)
	private java.sql.Timestamp createTime = new Timestamp(System.currentTimeMillis());
	/**
	 * 最后修改时间 db_column: last_update
	 */
	@Column("last_update")
	@ColDefine(insert = false, update = false)
	private java.sql.Timestamp lastUpdate;

	@Many(target = IndicatorProvinceDatasource.class, field = "indicatorProvinceId")
	private List<IndicatorProvinceDatasource> indicatorSources;

	// columns END

	// 视图属性

	/**
	 * 是否父对象
	 */
	private boolean isParent;

	public boolean isParent() {
		isParent = code.length() == 5 ? false : true;
		return isParent;
	}

	public String getSourcesVal() {
		String result;
		if (indicatorSources == null) {
			result = "";
		} else {
			List<Integer> sourceIds = Lists.newArrayList();
			for (IndicatorProvinceDatasource source : indicatorSources) {
				sourceIds.add(source.getDatasource());
			}
			result = StringUtils.join(sourceIds, ",");
		}
		return result;

	}

}
